﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrbaCommerce.ABM_Rol
{
    public partial class frm_roles : Form
    {
        public frm_roles()
        {
            InitializeComponent();
        }

        private void btn_crear_Click(object sender, EventArgs e)
        {
            frm_crearRol frm_crearRol = new frm_crearRol();
            frm_crearRol.ShowDialog();
        }

        private void frm_roles_Load(object sender, EventArgs e)
        {
            cargar_cmbRoles();
        }

        private void cargar_cmbRoles()
        {
            BaseDeDatos baseDeDatos = BaseDeDatos.Instance;
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.CommandText = "LOS_GDDES.SP_TRAER_ROLES_TODOS";
            DataTable dt_rol = baseDeDatos.consulta(sqlCommand);
            cmb_rol.DataSource = dt_rol;
            cmb_rol.DisplayMember = "NOMBRE";
            cmb_rol.ValueMember = "ID_ROL";
        }

        private void btn_Salir_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Para actualizar los cambios, desconectarse de la cuenta y volverse a conectar");
            this.Close();
        }

        private void btn_eliminar_Click(object sender, EventArgs e)
        {
            BaseDeDatos baseDeDatos = BaseDeDatos.Instance;
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "LOS_GDDES.SP_BAJA_ROL";
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.Clear();
            sqlCommand.Parameters.AddWithValue("@id_rol", cmb_rol.SelectedValue);
            baseDeDatos.ejecuta(sqlCommand);
            MessageBox.Show("Rol dado de baja");
        }

        private void btn_modificar_Click(object sender, EventArgs e)
        {
            frm_modificarRol frm_modificarRol = new frm_modificarRol(cmb_rol.Text, cmb_rol.SelectedValue.ToString()); 
            frm_modificarRol.ShowDialog();
        }

       
        private void cmb_rol_DropDown(object sender, EventArgs e)
        {
            cargar_cmbRoles();
        }    
    }
}